package com.guli.member.web;

import com.alibaba.fastjson.TypeReference;
import com.guli.common.utils.R;
import com.guli.common.vo.CouponVo;
import com.guli.member.feign.CouponFeignService;
import com.guli.member.feign.OrderFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author zzb
 * @Date 2024/4/22 23:19
 * @Version 1.0
 */
@Controller
public class MemberWebController {
    @Autowired
    private OrderFeignService orderFeignService;
    @Autowired
    private CouponFeignService couponFeignService;

    @GetMapping("/memberOrder.html")
    public String memberOrderPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                  Model model) {
        Map<String, Object> page = new HashMap<>();
        page.put("page", pageNum.toString());
        R r = orderFeignService.listWithItem(page);
        model.addAttribute("orders", r);
        return "orderList";
    }

    @GetMapping("/couponList.html")
    public String couponList(Model model) {
        R memberCoupons = couponFeignService.getMemberCoupons();
        List<CouponVo> couponVos = memberCoupons.getData(new TypeReference<List<CouponVo>>() {
        });
        R couponCatch = couponFeignService.getCouponCatch();
        List<CouponVo> couponVoList = couponCatch.getData(new TypeReference<List<CouponVo>>() {
        });
        model.addAttribute("couponVos", couponVos).addAttribute("catchCoupons", couponVoList);
        return "couponList";
    }

}
